'use strict';
define([
    'angular',
    'ngRoute',
    'services/getApiServices',
], function(angular) {
    return angular.module('myApp.login', [
            'ngRoute',
        ])
        .config(['$routeProvider', function($routeProvider) {
            $routeProvider.when('/login', {
                templateUrl: '../template/login.html',
                controller: 'loginCtrl'
            });
        }])
        .controller('loginCtrl', [
            '$scope',
            '$location',
            '$timeout',
            'ApiIterface',
            function($scope, $location, $timeout, ApiIterface) {
                $scope.userinfo = {
                    username: '',
                    userpass: ''
                };
                $scope.rev = null;
                $scope.login = () => {
                    console.log('this is from login web page', $scope.userinfo);
                    ApiIterface
                        .login($scope.userinfo)
                        .then(res => {
                            $scope.rev = res.data;
                            // console.log($location);
                            $timeout(() => {
                                $location.path('/tasks/all')
                            }, 2000)
                        })
                        .catch(err => console.log(err));
                }

            }
        ]);
});